<?php
/**
 * @ClassName: Cachetest
 * @Description: TODO
 * @author: wmsh
 * @Date: 2024-05-29 13:51
 * @Version: V1.0.0
 */

namespace app\test\controller\test;

use app\common\controller\Api;
use think\Db;
use think\facade\Cache;

class Cachetest extends Api
{
    protected $noNeedLogin = ['*'];

    public function redisSet()
    {
        var_dump('存Token');
        $encodeToken = $this->encode();
        $this->token = $encodeToken;
        var_dump($this->token);
        $payload = [
            'member_id' => $this->member_id,
            'login_time' => date_now(),
            'device_info' => \request()->server('http_user_agent')
        ];
        try {
            Cache::set('online', $encodeToken, $this->invalidationTime);  // 864000秒 等于10天
            Cache::set('payload', $payload);
        } catch (\Exception $e) {
            throw $e;
        }
    }

    public function redisGet()
    {
        var_dump('取Token');
        var_dump($this->token);
        $this->decode($this->token);
        var_dump($this->token);
        $token = Cache::get('online:' . $this->token);
        var_dump($token);
        $result = Cache::get('payload');
        var_dump($result);
    }

    public function getAdminInfo()
    {
        $admin_id = input('admin_id');
        var_dump(Db::name('admin_user')->where('id', $admin_id)->fetchSql()->find());
        $admin = Db::name('admin_user')->where('id', $admin_id)->find();
        var_dump($admin);
    }

}